package com.cloud.lan.entity.base;

import com.cloud.lan.entity.base.common.Page;
import com.cloud.lan.entity.base.common.PageResult;

import java.io.Serializable;

import lombok.Data;

/**
 * 分页统一出参
 * @author ErKang
 * @date Created in 2021/12/5 04:46
 * @title PageResponse.java
 * Department: Product development
 */
@Data
public class PageResponse<T> implements Serializable {

    public static final String OK = "00000";
    public static final String TOKEN_ERROR = "99991";
    public static final String ERROR = "99999";
    public static final String PARAMS_ILLEGAL = "99998";
    public static final String TOAST_ERROR = "300000";
    public static final String ROOM_STATUS_ERROR = "300001"; // 主播离开
    public static final String ROOM_STATUS_ERROR2 = "300002"; // 主播未开播
    public static final String ERROR_MSG = "系统异常";
    public static final String OK_MSG = "OK";
    private static final long serialVersionUID = 1L;
    private String code; // 默认无异常

    private String msg;

    private T data;

    private Page page;

    public PageResponse() {
        this.code = OK;
        this.msg = OK_MSG;
    }

    public PageResponse(T data) {
        this.code = OK;
        this.msg = OK_MSG;
        this.data = data;
    }

    public PageResponse(PageResult p) {
        Page page = new Page();
        page.setCurrentPage(p.getCurrentPage());
        page.setPageSize(p.getPageSize());
        page.setCount(p.getCount());
        this.code = OK;
        this.msg = OK_MSG;
        this.data = (T) p.getData();
        this.page = page;
    }

    public static PageResponse success(PageResult p) {
        Page page = new Page();
        page.setCurrentPage(p.getCurrentPage());
        page.setPageSize(p.getPageSize());
        page.setCount(p.getCount());
        PageResponse pageResponse = new PageResponse();
        pageResponse.code = OK;
        pageResponse.msg = OK_MSG;
        pageResponse.data = p.getData();
        pageResponse.page = page;
        return pageResponse;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

}
